package com.automannn.codeGenerator.core.parser.node;


import com.automannn.codeGenerator.core.context.InternalContextAdapter;
import com.automannn.codeGenerator.core.exception.MethodInvocationException;
import com.automannn.codeGenerator.core.exception.ParseErrorException;
import com.automannn.codeGenerator.core.exception.ResourceNotFoundException;
import com.automannn.codeGenerator.core.exception.TemplateInitException;
import com.automannn.codeGenerator.core.parser.Token;

import java.io.IOException;
import java.io.Writer;

/**
 * @author chenkh
 * @time 2020/12/7 10:30
 */
public interface Node {
    /*xxx: 子节点可以开始处理*/
    public void jjtOpen();

    /*xxx: 当前节点的所有子节点调用完成后进行调用*/
    public void jjtClose();

    /*xxx: 设置父节点*/
    public void jjtSetParent(Node n);

    /*xxx: 获取父节点*/
    public Node jjtGetParent();

    /*xxx: 添加子节点*/
    public void jjtAddChild(Node n, int i);

    /*xxx: 获取某个位置的子节点*/
    public Node jjtGetChild(int i);

    /*xxx: 获取子节点个数*/
    public int jjtGetNumChildren();

    /*xxx: 树的访问者接口*/
    public Object jjtAccept(ParserVisitor visitor, Object data);

    /*
     * ========================================================================
     * 不会被解析器自动生成，但是能够通过Velocity手动调用的方法
     * ========================================================================
     */

    /*xxx: 子节点的访问者接口*/
    public Object childrenAccept(ParserVisitor visitor, Object data);

    /*xxx: 获取第一个 码元*/
    public Token getFirstToken();

    /*xxx: 获取最后一个 码元*/
    public Token getLastToken();

    /*xxx: 获取码元类型*/
    public int getType();

    /*xxx: 初始化*/
    public Object init(InternalContextAdapter context, Object data) throws TemplateInitException;

    /*xxx: */
    public boolean evaluate( InternalContextAdapter context)
            throws MethodInvocationException;

    /*xxx: 节点值*/
    public Object value( InternalContextAdapter context)
            throws MethodInvocationException;

    /*xxx: 渲染*/
    public boolean render( InternalContextAdapter context, Writer writer)
            throws IOException,MethodInvocationException, ParseErrorException, ResourceNotFoundException;

    /*xxx: 执行*/
    public Object execute(Object o, InternalContextAdapter context)
            throws MethodInvocationException;

    /*xxx: 设置info*/
    public void setInfo(int info);

    /*xxx: 当前节点info*/
    public int getInfo();

    /*xxx: 字面值*/
    public String literal();

    /*xxx: 使当前节点非法*/
    public void setInvalid();

    /*xxx: 检测当前节点是否非法*/
    public boolean isInvalid();

    /*xxx: 获取当前行位置*/
    public int getLine();

    /*xxx: 获取当前列位置*/
    public int getColumn();

    /*xxx: 模板名称*/
    public String getTemplateName();
}
